import Vue from "vue";
import Vuex, { Commit, Dispatch } from "vuex";
import state from "./state";
import getters from "./getters";
import actions from "./actions";
import mutations from "./mutations";
import createPersistedState from "vuex-persistedstate";

Vue.use(Vuex);

export default new Vuex.Store({
  state,
  getters,
  mutations,
  actions,
  plugins: [
    createPersistedState({
      storage: window.localStorage,
      key: state.storageKey
      // reducer(val) {
      //     return {
      //         // 只储存state中的token
      //         token: val.token
      //     };
      // }
    })
  ]
});

//针对action设置:  action进行dispatch请求,然后commit到mutations修改state中数据
export interface ActionContextBase {
  commit: Commit;
  dispatch: Dispatch;
}
